#!/usr/bin/env python
# coding: utf-8

# In[6]:


import pandas as pd


# In[7]:


import numpy as np


# In[8]:


pd.__version__


# In[9]:


df_csv = pd.read_csv('C:/Users/pc/Desktop/data_analysis-master/week04/data/learn_pandas.csv')
df_csv


# In[10]:


df_txt = pd.read_table('C:/Users/pc/Desktop/data_analysis-master/week04/data/my_table.txt')


# In[11]:


df_txt


# In[12]:


df_excel = pd.read_excel('C:/Users/pc/Desktop/data_analysis-master/week04/data/my_excel.xlsx')
df_excel


# In[14]:


pd.read_table('C:/Users/pc/Desktop/data_analysis-master/week04/data/my_table.txt',header=None)


# In[17]:


df_csv = pd.read_csv('C:/Users/pc/Desktop/data_analysis-master/week04/data/learn_pandas.csv')
df_csv


# * 计算身高平均值

# In[62]:


df['Height'].mean()


# In[65]:


df['School'].value_counts()


# In[19]:


df = pd.read_csv('C:/Users/pc/Desktop/data_analysis-master/week04/data/learn_pandas.csv')


# In[20]:


df.columns


# In[22]:


df = df[df.columns[:7]]
df.head(2)


# In[23]:


df.tail(3)


# In[24]:


df.info()


# In[25]:


df.describe()


# In[27]:


df['School'].unique()


# In[80]:


df['School'].nunique()


# In[81]:


df['School'].value_counts()


# * 请计算：所有学校的身高、体重、的均值、最大值、最小值

# In[94]:


df_Tsinghua = df.query('School == "Tsinghua University"')
df_Tsinghua


# In[95]:


df_Tsinghua_male = df.query('School == "Tsinghua University" and Gender =="Male"')
df_Tsinghua_male


# In[93]:


df_Tsinghua_male['Height'].mean()


# ## 3.1 Groupby

# In[102]:


df.groupby(['School','Gender']).agg({'Height': 'mean','Weight':'mean'})


# - - - - 

# In[33]:


hurun_djs = pd.read_html('https://www.hurun.net/zh-CN/Info/Detail?num=L9SQPH9FKJB1')[-3]


# In[34]:


hurun_djs


# In[37]:


hurun_djs[0:101]


# In[39]:


hurun_djs[0:1].values.tolist()[0]


# * columns的重新命名 ：rename（将表头的0-7重新命名为上述“排名..."）

# In[42]:


df_hurun = hurun_djs[1:]
df_hurun


# In[54]:


hurun_djs[0:1].values.tolist()[0]


# In[55]:


df_hurun = hurun_djs[1:]
df_hurun


# In[57]:


df_hurun.columns = hurun_djs[0:1].values.tolist()[0]
df_hurun


# * 有多少个国家？
# * 有多少个城市？ 数量如何可以在地图上面用颜色变现出来？
# * 有多少个行业？

# In[59]:


df_hurun['国家'].unique() 


# In[60]:


df_hurun['行业'].unique()


# In[64]:


df_hurun['国家'].value_counts()


# In[67]:


df_hurun['行业'].value_counts()


# In[106]:


df_hurun['价值（亿元人民币）'] = df_hurun['价值（亿元人民币）'].astype('int64')


# In[107]:


df_hurun.info()


# In[110]:


df_hurun.groupby('国家').agg({'价值（亿元人民币）':'sum'})


# In[ ]:




